<?php

/**
 * This is the model class for table "pedido".
 *
 * The followings are the available columns in table 'pedido':
 * @property integer $pedido_id
 * @property integer $usuario_id
 * @property integer $talla_id
 * @property integer $ref_id
 * @property integer $cantidad
 * @property string $vendedorcodigo
 * @property string $nombrecliente
 * @property string $direccioncliente
 * @property string $telefcliente
 * @property string $ciudad
 * @property string $estado
 * @property string $observaciones
 * @property string $fechapedido
 * @property string $condpago
 * @property integer $status
 *
 * The followings are the available model relations:
 * @property Ref $ref
 * @property Talla $talla
 * @property Usuario $usuario
 */
class Pedido extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'pedido';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('usuario_id, talla_id, ref_id', 'required'),
			array('usuario_id, talla_id, ref_id, cantidad, status', 'numerical', 'integerOnly'=>true),
			array('vendedorcodigo, nombrecliente, telefcliente, ciudad, estado, condpago', 'length', 'max'=>40),
			array('direccioncliente', 'length', 'max'=>100),
			array('observaciones', 'length', 'max'=>80),
			array('fechapedido', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('pedido_id, usuario_id, talla_id, ref_id, cantidad, vendedorcodigo, nombrecliente, direccioncliente, telefcliente, ciudad, estado, observaciones, fechapedido, condpago, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'ref' => array(self::BELONGS_TO, 'Ref', 'ref_id'),
			'talla' => array(self::BELONGS_TO, 'Talla', 'talla_id'),
			'usuario' => array(self::BELONGS_TO, 'Usuario', 'usuario_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'pedido_id' => 'Pedido',
			'usuario_id' => 'Usuario',
			'talla_id' => 'Talla',
			'ref_id' => 'Ref',
			'cantidad' => 'Cantidad',
			'vendedorcodigo' => 'Vendedorcodigo',
			'nombrecliente' => 'Nombrecliente',
			'direccioncliente' => 'Direccioncliente',
			'telefcliente' => 'Telefcliente',
			'ciudad' => 'Ciudad',
			'estado' => 'Estado',
			'observaciones' => 'Observaciones',
			'fechapedido' => 'Fechapedido',
			'condpago' => 'Condpago',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('pedido_id',$this->pedido_id);
		$criteria->compare('usuario_id',$this->usuario_id);
		$criteria->compare('talla_id',$this->talla_id);
		$criteria->compare('ref_id',$this->ref_id);
		$criteria->compare('cantidad',$this->cantidad);
		$criteria->compare('vendedorcodigo',$this->vendedorcodigo,true);
		$criteria->compare('nombrecliente',$this->nombrecliente,true);
		$criteria->compare('direccioncliente',$this->direccioncliente,true);
		$criteria->compare('telefcliente',$this->telefcliente,true);
		$criteria->compare('ciudad',$this->ciudad,true);
		$criteria->compare('estado',$this->estado,true);
		$criteria->compare('observaciones',$this->observaciones,true);
		$criteria->compare('fechapedido',$this->fechapedido,true);
		$criteria->compare('condpago',$this->condpago,true);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Pedido the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
